// HTTP Request Type
var COMMENT_PASS = "COMMENT_PASS";
var COMMENT_FAIL = "COMMENT_FAIL";


function loadSucCommentList() {
	
	$("#commentPageForm_verifyStatus").combobox({
		panelHeight : 145,
		data : getAllCommentVerifyStatusData(),
		value : 0
	});
	
	getAllCaseTitleData();
	
	$("#commentList").datagrid({
		// title:'查询申请管理',
		fit : true,
		striped : true,// 设置为true将交替显示行背景
		border : false,
		fitColumns : true,
		nowrap : false,
		loadMsg : "正在加载中。。。",
	    columns: [[
               	{ field: 'caseName', title: '案例', width: 120,align:'center' , formatter:caseNameFormatter},
	   			{ field: 'guestName', title: '姓名', width: 40,align:'center' },
	   			{ field: 'guestPhone', title: '电话', width: 50,align:'center' },
	   			{ field: 'guestIp', title: 'IP地址', width: 60,align:'center' },
	   			{ field: 'content', title: '留言内容', width: 120,align:'center' },
	   			{ field: 'commentDate', title: '留言时间', width: 50,align:'center' },
	   			{ field: 'verifyResult', title: '审核结果', width: 40,align:'center', formatter:statusFormatter },
	   			{ field: 'edit', title: '操作', width: 60,align:'center', formatter:actionFormatter }
       ]],
       rownumbers : true, // 行号
	   singleSelect : true, // 是否单选
	   pagination : true,// 分页控件
	   pageSize : 20,
	   onLoadSuccess : onLoadSuccess
	});
	queryComment(1, 20);
	$(".panel-tool").hide();
}

// 查询申请管理列表
function queryComment(pageNum,pageSize){
	var commentPageForm =$("form[name='commentPageForm']");
	var url ='LoadCommentList';
	//$currentCaseId = $("#commentPageForm_caseId").combobox("getValue");
	var param =  $("form[name='commentPageForm']").serialize();
	param += '&pageNum='+pageNum+"&pageSize="+pageSize+"&type=admin"+"&currentCaseId="+$currentCaseId;
	loadDataGirdJson(url,param,'#commentList');
}

//重置后查询所有
function queryCommentDefault(){
	$currentCaseId = 0;
	$("#commentPageForm_caseId").combobox("setValue", "0");
	$("input[name='guestName']").val("");
	$("input[name='commentContent']").val("");
	$("#commentPageForm_verifyStatus").combobox("setValue", "0");
	queryComment(1,20);
}

function actionFormatter(data,row,index){
	var v1 = "";
	v1 = "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" " +
			" onclick=\"manageComment('"+row.commentId+"' , '" + COMMENT_PASS + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">通过</span></span></a>"
	v1 += "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton l-btn l-btn-plain\" data-options=\"toggle:true\" " +
		" onclick=\"manageComment('"+row.commentId+"' , '" + COMMENT_FAIL + "')\"><span style=\"color:blue\" class=\"l-btn-left\"><span class=\"l-btn-text\">不通过</span></span></a>"
	return v1;
}

function manageComment(commentId, manageType){
	
	$.post("ManageComment", {commentId : commentId, manageType : manageType}, function(text) {
		var data = (new Function("return "+text))();
		alert(data.status);
		if (data.status.indexOf('成功')) {
			queryComment(1, 20);
		}
	});
}

function statusFormatter(data, row, index) {
	var currentStatus = "";
	if (row.verifyResult == 0) {
		currentStatus = "待审核";
	} else if (row.verifyResult == 1) {
		currentStatus = "已通过";
	} else if (row.verifyResult == -1) {
		currentStatus = "未通过";
	}
	return currentStatus;
}

function caseNameFormatter(data, row, index) {
	if($currentCaseId > 0) {
			$("input[name='caseName']").val(row.caseName);
	}
	
	return row.caseName;
}